package com.wjy.Data_Structure.sort.sort2;

import java.util.Arrays;

import com.wjy.Data_Structure.sort.DataWrap;

public class BubbleSort {
	//冒泡排序
	public static void bubbleSort(DataWrap[] data) {
		System.out.println("排序开始");
		int arrayLength = data.length;
		for (int i = 0; i < arrayLength - 1; i++) {
			boolean flag = false;
			for (int j = 0; j < arrayLength - 1 - i; j++) {
				if (data[j].compareTo(data[j + 1]) > 0) {
					DataWrap tmp = data[j + 1];
					data[j + 1] = data[j];
					data[j] = tmp;
					flag = true;
				}
			}
			System.out.println(Arrays.toString(data));
			if (!flag) {
				break;
			}
		}

	}

	public static void main(String[] arys) {
		DataWrap[] data = { new DataWrap(21, ""), new DataWrap(30, ""), new DataWrap(49, ""), new DataWrap(30, ""),
				new DataWrap(16, ""), new DataWrap(9, ""), };
		System.out.println("排序之前：\n" + Arrays.toString(data));
		bubbleSort(data);
		System.out.println("排序之后：\n" + Arrays.toString(data));
	}
}
